package com.doubao.doubao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.doubao.doubao.common.api.ApiResult;
import com.doubao.doubao.mapper.BmsAffairrsMapper;
import com.doubao.doubao.mapper.BmsReFilesMapper;
import com.doubao.doubao.model.entity.BmsAffairs;
import com.doubao.doubao.model.entity.BmsNewGroup;
import com.doubao.doubao.model.entity.BmsReFiles;
import com.doubao.doubao.model.vo.AffairsVO;
import com.doubao.doubao.model.vo.GroupVO;
import com.doubao.doubao.service.IBmsAffairservice;
import com.doubao.doubao.service.IBmsReFilesService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/AffFiles")
public class BmsReFilesController extends BaseController {

    @Resource
    private IBmsReFilesService iBmsReFilesService;
    @Resource
    BmsReFilesMapper bmsReFilesMapper;


    @RequestMapping(value = "/getAffair", method = RequestMethod.GET)
    public ApiResult<?> findPage(@RequestParam(value = "affairsid", defaultValue = "1")Integer affairsid,
                                 @RequestParam(value = "userid", defaultValue = "1")String userid){
        List<Map<String, Object>> BookPage =  bmsReFilesMapper.selectMaps(new LambdaQueryWrapper<BmsReFiles>()
                .eq(BmsReFiles::getAffairsId, affairsid)
                .eq(BmsReFiles::getUserId, userid)
        );
        return ApiResult.success(BookPage);
    }

    @RequestMapping(value = "/getAllAffairList", method = RequestMethod.GET)
    public ApiResult<?> findPage(@RequestParam(value = "affairsid", defaultValue = "1")Integer affairsid){
        List<Map<String, Object>> AffairPage =  bmsReFilesMapper.selectMaps(new LambdaQueryWrapper<BmsReFiles>()
                .eq(BmsReFiles::getAffairsId, affairsid)
        );
        return ApiResult.success(AffairPage);
    }


    @PostMapping("/addAffairsWork")
    public ApiResult<BmsReFiles> addAffairs(@RequestBody BmsReFiles bmsReFiles) {
        iBmsReFilesService.save(bmsReFiles);
        return ApiResult.success(bmsReFiles);
    }

    @DeleteMapping("/delete/{id}")
    public ApiResult<?> delete(@PathVariable Long id){
        bmsReFilesMapper.deleteById(id);
        return ApiResult.success();
    }


}
